home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / Miro_Downloader.exe / platformcfg.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-11-12  |  4.9 KB  |  164 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. import os
  5. import util
  6. import config
  7. import _winreg
  8. import cPickle
  9. import string
  10. import prefs
  11. import tempfile
  12. import ctypes
  13. import resources
  14. import proxyfind
  15. proxy_info = proxyfind.get_proxy_info()
  16. _specialFolderCSIDLs = {
  17.     'AppData': 26,
  18.     'My Music': 13,
  19.     'My Pictures': 39,
  20.     'My Videos': 14,
  21.     'My Documents': 5,
  22.     'Desktop': 0,
  23.     'Common AppData': 35 }
  24.  
  25. def getSpecialFolder(name):
  26.     """Get the location of a special folder.  name should be one of the
  27.     following: 'AppData', 'My Music', 'My Pictures', 'My Videos', 
  28.     'My Documents', 'Desktop'.
  29.  
  30.     The path to the folder will be returned, or None if the lookup fails
  31.  
  32.     """
  33.     buf = ctypes.create_unicode_buffer(260)
  34.     buf2 = ctypes.create_unicode_buffer(1024)
  35.     SHGetSpecialFolderPath = ctypes.windll.shell32.SHGetSpecialFolderPathW
  36.     GetShortPathName = ctypes.windll.kernel32.GetShortPathNameW
  37.     csidl = _specialFolderCSIDLs[name]
  38.     if SHGetSpecialFolderPath(None, buf, csidl, False):
  39.         if GetShortPathName(buf, buf2, 1024):
  40.             return buf2.value
  41.         else:
  42.             return buf.value
  43.     else:
  44.         return None
  45.  
  46. _appDataDirectory = getSpecialFolder('AppData')
  47. _commonAppDataDirectory = getSpecialFolder('Common AppData')
  48. _baseMoviesDirectory = getSpecialFolder('My Videos')
  49. _nonVideoDirectory = getSpecialFolder('Desktop')
  50. if _baseMoviesDirectory is None:
  51.     _baseMoviesDirectory = os.path.join(getSpecialFolder('My Documents'), 'My Videos')
  52.  
  53.  
  54. def _getMoviesDirectory():
  55.     path = os.path.join(_baseMoviesDirectory, config.get(prefs.SHORT_APP_NAME))
  56.     
  57.     try:
  58.         os.makedirs(os.path.join(path, 'Incomplete Downloads'))
  59.     except:
  60.         pass
  61.  
  62.     return path
  63.  
  64.  
  65. def _getSupportDirectory():
  66.     path = os.path.join(_appDataDirectory, u'Participatory Culture Foundation', u'Miro', u'Support')
  67.     
  68.     try:
  69.         os.makedirs(path)
  70.     except:
  71.         pass
  72.  
  73.     return path
  74.  
  75.  
  76. def _getThemeDirectory():
  77.     path = os.path.join(_commonAppDataDirectory, u'Participatory Culture Foundation', u'Miro', u'Themes')
  78.     
  79.     try:
  80.         os.makedirs(path)
  81.     except:
  82.         pass
  83.  
  84.     return path
  85.  
  86.  
  87. def _getConfigFile():
  88.     return os.path.join(_getSupportDirectory(), 'preferences.bin')
  89.  
  90.  
  91. def load():
  92.     
  93.     try:
  94.         file = _getConfigFile()
  95.         if os.path.exists(file):
  96.             return cPickle.load(open(file))
  97.         else:
  98.             return { }
  99.     except:
  100.         import traceback
  101.         print 'Error loading perferences. Resetting prefs.'
  102.         traceback.print_exc()
  103.         return { }
  104.  
  105.  
  106.  
  107. def save(data):
  108.     file = _getConfigFile()
  109.     cPickle.dump(data, open(file, 'w'))
  110.  
  111.  
  112. def get(descriptor):
  113.     if descriptor == prefs.MOVIES_DIRECTORY:
  114.         return _getMoviesDirectory()
  115.     elif descriptor == prefs.THEME_DIRECTORY:
  116.         return _getThemeDirectory()
  117.     elif descriptor == prefs.NON_VIDEO_DIRECTORY:
  118.         return _nonVideoDirectory
  119.     elif descriptor == prefs.GETTEXT_PATHNAME:
  120.         return resources.path('locale')
  121.     elif descriptor == prefs.SUPPORT_DIRECTORY:
  122.         return _getSupportDirectory()
  123.     elif descriptor == prefs.ICON_CACHE_DIRECTORY:
  124.         return os.path.join(_getSupportDirectory(), 'icon-cache')
  125.     elif descriptor == prefs.DB_PATHNAME:
  126.         path = get(prefs.SUPPORT_DIRECTORY)
  127.         return os.path.join(path, 'tvdump')
  128.     elif descriptor == prefs.BSDDB_PATHNAME:
  129.         path = get(prefs.SUPPORT_DIRECTORY)
  130.         return os.path.join(path, 'database')
  131.     elif descriptor == prefs.SQLITE_PATHNAME:
  132.         path = get(prefs.SUPPORT_DIRECTORY)
  133.         return os.path.join(path, 'sqlitedb')
  134.     elif descriptor == prefs.LOG_PATHNAME:
  135.         return os.path.join(tempfile.gettempdir(), '%s.log' % config.get(prefs.SHORT_APP_NAME))
  136.     elif descriptor == prefs.DOWNLOADER_LOG_PATHNAME:
  137.         return os.path.join(tempfile.gettempdir(), '%s-downloader.log' % config.get(prefs.SHORT_APP_NAME))
  138.     elif descriptor == prefs.RUN_AT_STARTUP:
  139.         folder = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, 'Software\\Microsoft\\Windows\\CurrentVersion\\Run')
  140.         count = 0
  141.         while True:
  142.             
  143.             try:
  144.                 (name, val, type) = _winreg.EnumValue(folder, count)
  145.                 count += 1
  146.                 if name == config.get(prefs.LONG_APP_NAME):
  147.                     return True
  148.             continue
  149.             return False
  150.             continue
  151.  
  152.         return False
  153.     elif descriptor == prefs.HTTP_PROXY_ACTIVE:
  154.         return proxy_info.host is not None
  155.     elif descriptor == prefs.HTTP_PROXY_HOST:
  156.         return proxy_info.host
  157.     elif descriptor == prefs.HTTP_PROXY_PORT:
  158.         return proxy_info.port
  159.     elif descriptor == prefs.HTTP_PROXY_IGNORE_HOSTS:
  160.         return poxy_info.ignore_hosts
  161.     else:
  162.         return descriptor.default
  163.  
  164.